﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace iNet.Media.Imaging
{
	/// <summary>
	/// PNG 影像解碼工作工廠。
	/// </summary>
	public class PngImageDecodeTaskFactory : FastImageDecodeTaskFactory
	{
		#region 建構子
		/// <summary>
		/// 初始化新的 PngImageDecodeTaskFactory 執行個體。
		/// </summary>
		public PngImageDecodeTaskFactory()
			: base("PNG Image DecodeTask Factory", ImageFormats.Png)
		{ }
		#endregion
		#region CreateDecodeTask
		public override MediaDecodeTask CreateDecodeTask(MediaStorage source)
		{
			return new PngImageDecodeTask(source);
		}
		#endregion
		#region IsSupportedFormatCore
		protected override bool IsSupportedFormatCore(byte[] mediaHeader)
		{
			if (mediaHeader.Length < 8)
				return false;
			return (BitConverter.BigEndian.ToUInt32(mediaHeader, 0) == 0x89504E47 && BitConverter.BigEndian.ToUInt32(mediaHeader, 4) == 0x0D0A1A0A);
		}
		#endregion
		#region MediaHeaderSize
		public override int MediaHeaderSize
		{
			get
			{
				return 8;
			}
		}
		#endregion
	}
}
